import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';

import '../../commont/button.dart';
import '../../commont/label.dart';
import '../../model/model_default.dart';
import '../../tool/assets.dart';

class AllMute extends StatefulWidget {
  void Function() onChange;

  AllMute({super.key, required this.onChange});

  @override
  State<AllMute> createState() => _AllMuteState();
}

class _AllMuteState extends State<AllMute> {
  Widget item(bool isadd) {
    return SizedBox(
      width: 18 * GlobalConfig.scaleH,
      height: 18 * GlobalConfig.scaleH,
      child: imgButton(
          groundColor: Color_bg_view,
          enable: true,
          img: Image.asset(isadd ? assets.add : assets.sum, color: Colors.black),
          onClick: () {
            setState(() {
              globalModel.db = isadd ? globalModel.db + 1 : globalModel.db - 1;
              globalModel.db = max(globalModel.db, globalModel.min_db);
              globalModel.db = min(globalModel.db, globalModel.max_db);
            });
            widget.onChange();
          }),
    );
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 65 * GlobalConfig.scaleH,
      child: Row(
        children: [
          SizedBox(
            width: 35 * GlobalConfig.scaleH,
            height: 35 * GlobalConfig.scaleH,
            child: imgButton(
                groundColor: Color_bg_view,
                img: Image.asset(assets.VOL, color: Colors.black),
                borderWidth: 0,
                shadowRadius: 0,
                onClick: null),
          ),
          const SizedBox(width: 5),
          SizedBox(
              width: 40,
              height: 20 * GlobalConfig.scaleH,
              child: Label(
                '${globalModel.db}dB',
                fontsize: 13,
                textColor: Colors.black,
                borderColor: Colors.black,
              )),
          const SizedBox(width: 5),
          item(false),
          const SizedBox(width: 2),
          Expanded(
              child: kSlider(
            value: globalModel.db.toDouble(),
            min: globalModel.min_db.toDouble(),
            max: globalModel.max_db.toDouble(),
            activeColor: Color_theme,
            thumbColor: Color_theme,
            enable: true,
            onChanged: (p0) {
              setState(() {
                globalModel.db = ((p0 * 100) / 100.0).toInt();
              });
            },
            onChangedForSend: (p0) {
              widget.onChange();
            },
          )),
          const SizedBox(width: 2),
          item(true),
          const SizedBox(width: 5),
          SizedBox(
              width: 40,
              height: 20 * GlobalConfig.scaleH,
              child: kTextButton(
                name: 'Mute',
                groundColor: globalModel.mute ? Color_theme : Color_bg_view,
                borderColor: globalModel.mute ? Color_theme : Color_text,
                textColor: globalModel.mute ? Colors.white : Color_text,
                enable: true,
                onClick: (p0) {
                  setState(() {
                    globalModel.mute = !globalModel.mute;
                  });
                  widget.onChange();
                },
              )),
        ],
      ),
    );
  }
}
